package com.awesumgames.awesum;

import java.util.EnumSet;

import com.awesumgames.awesum.sprites.Sprite;

import android.opengl.GLES20;
import android.opengl.Matrix;

public class Layer2d extends Layer {
	public enum TraitFlag { Phys(1);
		public int flag = 0;
		TraitFlag(int f) {this.flag = f;}
		public static TraitFlag from(int x) {
	        switch (x) {
		        case 1:
		            return Phys;
	        }
	        return null;
	    }
	}
	public EnumSet<TraitFlag> traits(int ts) {
		EnumSet<TraitFlag> traitSet = EnumSet.noneOf(TraitFlag.class);
		for (int i = 0; i < TraitFlag.values().length; i++) {
			int val = TraitFlag.values()[i].flag;
			if ((val & ts) == val)
				traitSet.add(TraitFlag.values()[i]);
		}
		return traitSet;
	}

	@Override
	public void add(Runnable r) {
		children.add(r);
	}
	/*public void add(Sprite s) {
		children.add((Runnable)s);
	}*/

	@Override
	public void remove(Runnable r) {
		children.remove(r);
	}
	public void remove(Sprite s) {
		children.remove(s);
	}
	
	public void load(int traitFlags) {
		//Awesum.debug("load 2d layer start");
		EnumSet<TraitFlag> tSet = traits(traitFlags);
		//if (tSet.contains(TraitFlag.Phys))	phys = new TraitPhys(this);
		
		super.load();
		//Awesum.debug("load 2d layer end");
	}
	
	public void draw() {
		Matrix.setLookAtM(Game.viewMatrix, 0,		0f, 0f, 0f,		0f, 0f, -5f,		0f, 1f, 0f);
		GLES20.glDisable(GLES20.GL_CULL_FACE);
		GLES20.glDisable(GLES20.GL_DEPTH_TEST);
		GLES20.glEnable(GLES20.GL_BLEND);
		GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
		
		Game.setProjection2d();
		
		super.draw();
	}
}
